package com.movecar.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.movecar.R;
import com.movecar.model.Pictures;
import com.movecar.utils.AppConfig;
import com.movecar.utils.imageloader.Constants;
import com.nostra13.universalimageloader.core.ImageLoader;

public class ImageAdapter extends BaseAdapter {

	Activity activity;
	private LayoutInflater inflater;
	private ViewHolder viewHolder = null;
	ImageLoader imageLoader = null;
	ArrayList<Pictures> picturesData = new ArrayList<Pictures>();
	

	public ImageAdapter(Activity activity, ArrayList<Pictures> picturesData) {

		this.activity = activity;
		this.picturesData = picturesData;
		inflater = LayoutInflater.from(activity);

		imageLoader = ImageLoader.getInstance();
		imageLoader.init(Constants.imageLoaderConfiguration(activity));
	}

	@Override
	public int getCount() {

		return picturesData.size();
	}

	@Override
	public Object getItem(int arg0) {

		return picturesData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {

		return picturesData.size();
	}

	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		View itemView = null;
		// if (view == null) {
		// viewHolder = new ViewHolder();
		view = inflater.inflate(R.layout.home_img_item, arg2, false);
		itemView = view;
		// view.setTag(itemView);

		// viewHolder.mImageView = (ImageView)
		// view.findViewById(R.id.mImageView);

		// view.setTag(viewHolder);
		// } else {
		// itemView = (View) view.getTag();
		// // viewHolder = (ViewHolder) view.getTag();
		// }
		// viewHolder.mImageView.setImageResource(R.drawable.default_user_photo);
		ImageView mImageView = (ImageView) itemView.findViewById(R.id.mImageView);
		if (null != picturesData.get(position).getUrl()) {
			imageLoader.displayImage(AppConfig.HOST + picturesData.get(position).getUrl(), mImageView,
					Constants.image_display_options, AppConfig.animateListener);

		}

		return view;
	}

	class ViewHolder {

		ImageView mImageView;
	}
}
